class Transaction < ApplicationRecord
  belongs_to :order, foreign_key: :order_no, primary_key: :order_no
  has_one :appointment, through: :order, source: :appointment
  has_one :store, through: :order, source: :store
  has_one :company, through: :order, source: :company

  belongs_to :camp_order, foreign_key: :order_no, primary_key: :order_no
  has_one :camp_appointment, through: :camp_order, source: :appointment
  has_one :camp_store, through: :camp_order, source: :store

  belongs_to :campaigns_order, class_name: 'Campaigns::Order', foreign_key: :order_no, primary_key: :order_no
  has_one :campaigns_appointment, class_name: "Campaigns::Appointment", through: :campaigns_order, source: :appointment

  enum status: [:pending, :refunded]
  before_save {false}
  class << self
    def csv
      csv_builder = ActiveAdmin::CSVBuilder.new
      csv_builder.column :id
      csv_builder.column("Name") {|resource| resource.full_name}
      CustomField.users.each do |field|
        csv_builder.column(field.label) {|user| user.data[field.label] if user.data}
      end
      csv_builder
    end
  end

end
